package com.ruoyi.project.business.timeperiod.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.project.business.timeperiod.entity.TimePeriod;
import com.ruoyi.project.business.timeperiod.mapper.TimePeriodMapper;
import com.ruoyi.project.business.timeperiod.request.AddTimePeriodRequest;
import com.ruoyi.project.business.timeperiod.request.ListTimePeriodRequest;
import com.ruoyi.project.business.timeperiod.response.TimePeriodResponse;
import com.ruoyi.project.business.timeperiod.service.ITimePeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工作站Service业务层处理
 * 
 * @author ${author}
 * @date 2024-04-01
 */
@Service
public class TimePeriodServiceImpl implements ITimePeriodService {
    @Autowired
    private TimePeriodMapper timePeriodMapper;

    /**
     * 查询工作站
     * 
     * @return 工作站
     */
    @Override
    public TimePeriod selectTimePeriodById(Long id) {
        return timePeriodMapper.selectTimePeriodById(id);
    }

    /**
     * 查询工作站列表
     * 
     * @return 工作站
     */
    @Override
    public List<TimePeriodResponse> selectTimePeriodList(ListTimePeriodRequest request, Long tenantId) {
        // TODO request to  param
        TimePeriod param = BeanUtils.copy(request, TimePeriod.class);
        param.setTenantId(tenantId);
        List<TimePeriod> entitis = timePeriodMapper.selectTimePeriodList(param);
        List<TimePeriodResponse> resList = BeanUtils.copyList(entitis, TimePeriodResponse.class);
        return resList;
    }

    /**
     * 新增工作站
     * 
     * @return 结果
     */
    @Override
    public int insertTimePeriod(AddTimePeriodRequest request, Long operatorId, Long tenantId) {
        TimePeriod entity = BeanUtils.copy(request, TimePeriod.class);
        entity.setTenantId(tenantId);
        entity.setCreator(operatorId);
        entity.setDeleted(Boolean.FALSE);
        entity.setCreateTime(DateUtils.getNowDate());
        return timePeriodMapper.insertTimePeriod(entity);
    }

    /**
     * 修改工作站
     * 
     * @return 结果
     */
    @Override
    public int updateTimePeriod(TimePeriod entity, Long operatorId, Long tenantId) {
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setTenantId(tenantId);
        entity.setUpdater(operatorId);
        return timePeriodMapper.updateTimePeriod(entity);
    }

    /**
     * 批量删除工作站
     * 
     * @return 结果
     */
    @Override
    public int deleteTimePeriodByIds(Long[] ids, Long operatorId, Long tenantId) {
        return timePeriodMapper.deleteTimePeriodByIds(ids);
    }

    /**
     * 删除工作站信息
     * 
     * @return 结果
     */
    @Override
    public int deleteTimePeriodById(Long id, Long operatorId, Long tenantId) {
        return timePeriodMapper.deleteTimePeriodById(id);
    }
}
